home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: sscanf bug??????
- Date: Sat, 10 Feb 1996 21:22:34 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9602102022.AA01265@dxmint.cern.ch>
- References: <4fimvo$82s@fnord.dfw.net>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- jtmcap@dfw.dfw.net (Jerry Jackson) writes:
-
- >the following is a program compiled using microway ndp c/c++ compiler.
- >
- >#include <stdio.h>
- >#include <string.h>
- >
- >main()
- >{
- > char str_1[] = "013196";
- > char str_2[] = "13196";
- > long res_1, res_2;
- >
- > sscanf(str_1,"%d",&res_1);
- > sscanf(str_2,"%d",&res_2);
- >
- > printf("\nres_1 = %d",res_1);
- > printf("\nres_2 = %d",res_2);
- >}
- >
- >the output looks like this:
- >
- >res_1 = 89
- >res_2 = 13196
- >
- >microway says that the leading zero causes sscanf to do an octal
- >conversion on the integer. i have not found any documentation to verify
- >this. also other compilers that i use return the value 13196 for both
- >calls to sscanf.
- >
- >bug or undocumented feature?
-
- BUG. This is the correct behaviour for the %i conversion specifier,
- _not_ for %d.
-
- The Microway sscanf is broken and you should ask them to fix it as soon as
- possible (or to show you the paragraph from the standard which describes
- the behaviour of their implementation :-)
-
- OTOH, your code is broken, as well. %d expects a pointer to int, but you
- supply a pointer to long. Since this invokes undefined behaviour, your
- code cannot be used to prove that the Microway implementation is broken.
- Check your C book to find out the correct conversion descriptor for a long
- variable.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-